package com.guchenbo.lssp.pool;

import com.guchenbo.lssp.core.Session;

public class SessionHolder {
    protected volatile boolean discard = false;
    protected volatile boolean active = false;

    private final SessionSource sessionSource;
    private final Session session;
    /**
     * 是否是共享的session
     * 初始化的时候才是共享的
     */
    private boolean isShared;

    protected SessionHolder(SessionSource sessionSource, Session session) {
        this.sessionSource = sessionSource;
        this.session = session;
    }

    public boolean isDiscard() {
        return discard;
    }

    public void setDiscard(boolean discard) {
        this.discard = discard;
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public SessionSource getSessionSource() {
        return sessionSource;
    }

    public Session getSession() {
        return session;
    }

    public boolean isIdle() {
        return !isDiscard() && !isActive();
    }

    public boolean isShared() {
        return isShared;
    }

    public void setShared(boolean shared) {
        isShared = shared;
    }
}
